﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShortcutMenu
{
    public static class Reflection
    {
        public static Dictionary<Type, T>? Create<T>(Type[] ass)
        {
            Dictionary<Type, T> dict = new();
            foreach (var item in ass)
            {
                if (typeof(T).IsAssignableFrom(item))
                {
                    if (item.Name != typeof(T).Name)
                    {
                        dict.Add(item, (T)Activator.CreateInstance(item));
                    }
                }
            }
            return dict;
        }

        public static Dictionary<Type, T>? Create<T>(Type[] ass, params object?[]? args)
        {
            Dictionary<Type, T> dict = new();
            foreach (var item in ass)
            {
                if (typeof(T).IsAssignableFrom(item))
                {
                    if (item.Name != typeof(T).Name)
                    {
                        dict.Add(item, (T)Activator.CreateInstance(item, args));
                    }
                }
            }
            return dict;
        }
    }
}
